/**
 * @file
 * Attaches behaviors for the context_extend module.
 */

(function ($) {

/**
 * Implements Drupal.behaviors for the context_extend module.
 */

Drupal.behaviors.context_extend_add_block = {
  attach: function (context, settings) {
    $('#page', context).once(function () {
      if (Drupal.behaviors.context_extend_reaction_block.getUrlVariable('drag-drop') == 1) {
        $(this).prepend('<div id="context-extend-add-block-link">' + Drupal.t('Add block') +'</div>');
        var defaultContext = $('#context-extend-ui-editor').find('li.context-editable').attr('id').split('context-editable-trigger-')[1];
      }
      $('#context-extend-add-block-link').click(function(e) {
        $(this).hide();
        // Get context for edit
        $('#context-extend-disabled-blocks').removeClass('element-invisible').dialog({
          title: Drupal.t('Add block'),
          position: ['center','center'],
          buttons: {
            'Close': function() {
              $(this).dialog("close");
              $('#context-extend-add-block-link').show();
              $('#context-extend-add-block-link-close').hide();
            }
          },
          width: '500px'
        }).parent().css({position:'fixed'});

        $('#page:not(.context-extend-add-block)').addClass('context-extend-add-block').prepend('<div id="context-extend-add-block-link-close">' + Drupal.t('Off Add block') +'</div>');
        $('#context-extend-add-block-link-close').show();
        $('#context-extend-add-block-link-close').click(function(){
          $(this).hide();
          $('#context-extend-add-block-link').show();
          $('#context-extend-disabled-blocks').dialog('close');
        });

        e.preventDefault();
        return false;
      });
    });

  },
  deattach : function() {}
};

})(jQuery);
